package com.yk.framework.entity;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author lifetime
 * 
 */
public abstract class AbstractCoreBaseInfo implements ICoreBaseInfo {
	HashMap<String, Object> data = new HashMap<String, Object>();

	public String getString(String key) {
		Object obj = get(key);
		return obj == null ? null : obj.toString();
	}

	public Object get(String key) {
		return data.get(key);
	}

	public Boolean getBoolean(String key) {
		Object o = get(key);
		if (o == null) {
			return Boolean.FALSE;
		}
		if (o instanceof Boolean) {
			return (Boolean) o;
		}
		String str = o.toString();
		if ("true".equalsIgnoreCase(str) || "1".equalsIgnoreCase(str)) {
			return Boolean.TRUE;
		} else if ("false".equalsIgnoreCase(str) || "0".equalsIgnoreCase(str)) {
			return Boolean.FALSE;
		} else {
			throw new IllegalArgumentException(" getBoolean() param exception : value is " + str);
		}
	}

	public int getInt(String key) {
		Object o = get(key);
		if (o == null) {
			return Integer.MIN_VALUE;
		}
		if (o instanceof Integer) {
			return (Integer) o;
		}
		return Integer.parseInt(o.toString());
	}

	public BigDecimal getBigDecimal(String key) {
		Object o = get(key);
		if (o == null) {
			return null;
		}
		if (o instanceof BigDecimal) {
			return (BigDecimal) o;
		} else {
			return new BigDecimal(o.toString());
		}
	}

	public void put(String key, Object value) {
		data.put(key, value);
	}

	public void size() {
		data.size();
	}

	public Set<String> keys() {
		return data.keySet();
	}

	public boolean containKey(String key) {
		return data.containsKey(key);
	}

	public boolean containValue(Object value) {
		return data.containsValue(value);
	}

	public void addAll(Map<String, Object> map) {
		for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) {
			String key = (String) it.next();
			data.put(key, map.get(key));
		}
	}

}
